package com.focusai.efairy.business.manager;

import android.content.Context;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;

import com.focusai.efairy.EFApplication;
import com.focusai.efairy.model.manager.CacheManager;

/**
 * Created by luo_guangwen on 2017/9/1.
 */

public class BeedManager {
    public static void startpalyBeed(){
        if (shouldBeep(CacheManager.getUserMsgTip(),EFApplication.getContext())){
            Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone rt = RingtoneManager.getRingtone(EFApplication.getContext(), uri);
            rt.play();
        }
    }
    private static boolean shouldBeep(boolean should, Context activity) {
        boolean shouldPlayBeep = should;
        if (shouldPlayBeep) {
            // See if sound settings overrides this
            AudioManager audioService = (AudioManager) activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
            if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
                shouldPlayBeep = false;
            }
        }
        return shouldPlayBeep;
    }
}
